package com.windmill.core;

import iqq.im.QQException;
import iqq.im.core.QQContext;
import iqq.im.core.QQLifeCycle;

import java.util.HashMap;
import java.util.Map;

import com.windmill.bean.Card;
import com.windmill.bean.Compose;
import com.windmill.bean.Gift;
import com.windmill.bean.ThemeCard;

public class CardStore implements QQLifeCycle {
	private Map<Integer, Card> cardMap; // cardId ==> Card
	private Map<Integer, Gift> giftMap; // giftId ==> Gift
	private Map<Integer, ThemeCard> themeCardMap; //themeCardId ==> ThemeCard
	private Map<Integer, Compose> composeMap;	//cardId ==> Compose
	public CardStore(){
		this.cardMap = new HashMap<Integer,Card>();
		this.giftMap = new HashMap<Integer,Gift>();
		this.themeCardMap = new HashMap<Integer,ThemeCard>();
		this.composeMap = new HashMap<Integer,Compose>();
	}
	@Override
	public void init(QQContext context) {		
	}
	@Override
	public void destroy() throws QQException {
		// TODO Auto-generated method stub
		
	}
	public Map<Integer, Card> getCardMap() {
		return cardMap;
	}
	public void setCardMap(Map<Integer, Card> cardMap) {
		this.cardMap = cardMap;
	}
	public Map<Integer, Gift> getGiftMap() {
		return giftMap;
	}
	public void setGiftMap(Map<Integer, Gift> giftMap) {
		this.giftMap = giftMap;
	}
	public Map<Integer, ThemeCard> getThemeCardMap() {
		return themeCardMap;
	}
	public void setThemeCardMap(Map<Integer, ThemeCard> themeCardMap) {
		this.themeCardMap = themeCardMap;
	}
	public Map<Integer, Compose> getComposeMap() {
		return composeMap;
	}
	public void setComposeMap(Map<Integer, Compose> composeMap) {
		this.composeMap = composeMap;
	}
	
	public Card getCardById(int id){
		return this.cardMap.get(id);
	}
	public Gift getGiftById(int id){
		return this.giftMap.get(id);
	}
	public Gift getGiftByThemeIdAndSzType(int themeId,String szType){
		ThemeCard theme = this.themeCardMap.get(themeId);
		for(Gift gift:theme.getGift()){			
			if(gift.getSzTYPE_ID().equals(szType)){
				return gift;
			}
		}
		return null;
	}
	public ThemeCard getThemeById(int id){
		return this.themeCardMap.get(id);
	}
	public Compose getComposeByCardId(int id){
		return this.composeMap.get(id);
	}
	public Card getCardByName(String cardName) {
		for(Integer key:cardMap.keySet()){
			if(cardMap.get(key).getName().equals(cardName)){
				return cardMap.get(key);
			}
		}
		return null;
	}
}
